package com.example.lib_cson.mvvm.view;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.fragment.app.Fragment;

import com.example.lib_cson.mvvm.vm.BaseViewModel;

public abstract class BaseFragment<VM extends BaseViewModel,DB extends ViewDataBinding>extends Fragment {

    protected VM mViewModel;
    protected DB mDataBinding;
    protected abstract int byId();
    protected abstract VM getViewModel();
    protected abstract void initView();

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mDataBinding= DataBindingUtil.inflate(inflater,byId(),container,false);
        mViewModel=getViewModel();
        initView();
        return mDataBinding.getRoot();
    }
}
